Skip to content

Improvements to higher-kinded types #585

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 22 commits into from
May 25, 2015

Conversation

odersky
Copy link
Contributor

@odersky odersky commented May 18, 2015

Lots of improvements to higher-kinded types which prevent crashes, keep types in
beta-reduced form, and improve printlng of type lambdas. The motivating example
for most of these is the included test case Iterable.scala. The beta-reduction
was observed in method JavaParsers#basicType. I did not manage to minimize
the test case without reference to dotc itself. Review by @adriaanm

This PR is based on #573.

@scala-jenkins
Copy link

Can one of the admins verify this patch?

@DarkDimius
Copy link
Contributor

@scala-jenkins add to whitelist

@odersky
Copy link
Contributor Author

odersky commented May 20, 2015

/rebuild

@DarkDimius
Copy link
Contributor

@odersky tests will not succeed until #591 gets merged.

@adriaanm
Copy link
Contributor

To rebase, do this in your branch: git pull --rebase https://github.com/lampepfl/dotty.git master

(By the way, you can easily add the lampepfl remote using the hub wrapper for git: hub remote add lampepfl, or git remote add lampepfl https://github.com/lampepfl/dotty.git, so you don't have to write the remote url out in full.)

odersky added 22 commits May 21, 2015 17:41
Brings in line with Scala 2 spec.
This mimics scalac's behavior (but not the official syntax; in fact the
official syntax seems to be ambiguous.
Did not handle this case before.
Idea: when printing, we should be more lenient about conditions that
would otherwise cause an assertion failure, because we want to avoid
triggering further assertions while diagnosing previous errors. As a start
we generalize an assertion that RefinedTypes cannot be created after erasure.
This gets triggered when playing around with printing lambdas at erasure time
(see following commit): erasure runs at phase erasure + 1, so ctx.erasedTypes is true,
but we might still want to print lambdas then, and printing lambdas will create new
refined types as of next commit.
... makes diagnostics more legible.
Previously we could have returned true here yet a subsequent
lambdaArgIndex would fail with a Numberformat error. This scenario
is prevented now.
Need to generate new type if variance differs from old one.
Use the proposed Lambda syntax

  [HK$0, ..., HK$n] => body

for them.
testLifted widened a type to an some base type constructor when comparing with
a type lambda. This can return false positives if the widened type is on the
right of the comparison. The fix adds a parameter to testLifted indicating
whether widening is permitted.
This was uncovered by previous commit "Fix isSubType bug ...".
Also removed two redundants ".fresh" calls in "fresh.addMode".
The test case that caused all previous commits in this branch.
This gives us a cheap way to bound the search of all baseclasses in
testLifted.
lookupRefined now reduces fully instantiated lambdas.
It's a more logical home for them than the Context object.
Previously, this fell back to toString
As test case IterableDotty shows, there can be a cycle

  findMember  -->  &  -->  <:<  -->  hasMatchingMember -->  findMember

which leads to an infinite recursion. This commit avoids this by
keeping track of names of outstanding findMember searches and falling
back to forming AndTypes instead of `&' is we repeat a findMember
search on a name seen before after a certain recursion depth.
Displaying stuff should never report an exception or cause more messages to be displayed that
relate to the displaying.
More refular that way. Also, change some raw printlns in low-level
code to reporter.printlns in order to harden them against prints over prints.
Typecomparer is not a good place because it gets re-generated for new context,
which causes the counts to be reset.
Adds IterableSelfRec.scala which caused lockup of the compiler.
After a lot of work the problem was determined to be polyomial or
exponential behavior of the compiler when executing findMember
on refined types that contain several bindings where the
resutling & causes a recursive invokation of findMember with
the same name. We do have a stop for this now, but if the
stop comes too late the runtime will grow very fast.

Problem addressed by kiccking in earlier with the stopping logic.
@odersky odersky force-pushed the fix/collection-related branch from f6867c8 to 78640eb Compare May 21, 2015 15:42
@odersky
Copy link
Contributor Author

odersky commented May 21, 2015

rebased to current master

@DarkDimius
Copy link
Contributor

validate-junit is going to fail, due to somewhat wrong configuration of the runner. We need help from @adriaanm in fixing it, I've already contacted him, he should have a look soon.

@odersky
Copy link
Contributor Author

odersky commented May 21, 2015

/rebuild

@odersky
Copy link
Contributor Author

odersky commented May 21, 2015

Still no luck. Since I don't even have a proper computer to work with anymore I let someone else deal with the rebasings and retries.

@DarkDimius
Copy link
Contributor

/rebuild

@odersky odersky mentioned this pull request May 22, 2015
@odersky
Copy link
Contributor Author

odersky commented May 25, 2015

Going to merge because other unrelated fixes to existentials are likely to depend on this.

odersky added a commit that referenced this pull request May 25, 2015
@odersky odersky merged commit b2634a8 into scala:master May 25, 2015
@allanrenucci allanrenucci deleted the fix/collection-related branch December 14, 2017 19:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants